<template>
  <div class="icons">
    <swiper>
      <swiper-slide v-for="page of pages" :key="page.index">
        <div v-for="item of page" :key="item.id" class="icon">
          <div class="icon-img">
            <img class="icon-img-content" :src="item.imgUrl" alt="">
          </div>
          <p class="icon-dec">{{item.desc}}</p>
        </div>
      </swiper-slide>
    </swiper>
  </div>
  <!--v-for="item of iconList" :key="item.id"-->
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        let page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    }
  }
}
</script>

<style lang="scss" scoped>
  @import "~styles/varibles";
  @import "~styles/mixins";

  .icons /deep/ .swiper-container {
    height: 0;
    padding-bottom: 50%;
  }

  .icons {
    padding-bottom: .1rem;

    .icon {
      width: 25%;
      float: left;
      padding-bottom: 25%;
      position: relative;
      height: 0;

      .icon-img {
        position: absolute;
        top: 0;
        bottom: .44rem;
        left: 0;
        right: 0;
        box-sizing: border-box;
        padding: .1rem;

        .icon-img-content {
          height: 100%;
          display: block;
          margin: 0 auto;
        }
      }

      .icon-dec {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: .44rem;
        line-height: .44rem;
        text-align: center;
        @include ellipsis;
      }
    }
  }
</style>
